const { ListToNode, NodeToList, ListNode, timeL } = require("../utils.js");

/**
 * @param {number[]} nums
 * @return {number}
 */
var jump = function (nums) {
  let leng = nums.length,
    i = 0;
  if (!leng || leng === 1) return 0;
  while (leng) {
    i += 1;
    if (nums[0] >= leng - 1) return i;
    let item = nums
      .slice(1, nums[0] + 1)
      .map((item, index) => {
        return [item, index];
      })
      .sort((a, b) => b[0] + b[1] - a[0] - a[1])[0];
    leng -= item[1] + 1;
    nums = nums.splice(item[1] + 1);
  }
  return i;
};

let nums = [1, 1, 1, 1];

timeL(jump, [nums]);
